package operation;

import Book.Booklist;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:26554
 * Date:2024-11-17
 * Time:13:26
 */
public class BorrowOperation implements IOPeration{
    @Override
    public void work(Booklist booklist) {
        int ret = -1;
        System.out.println("借阅图书");
        System.out.println("请输入要借阅的书的书名");
        Scanner san = new Scanner(System.in);
        String BorrowBookName = san.nextLine();
        int currentsize = booklist.getActualbooks();
        for (int i = 0; i < currentsize; i++) {
            String name = booklist.getbook(i).getName();
            if(BorrowBookName.equals(name)){
                ret = i;
                break;
            }
        }
        if(ret!=-1){
            booklist.getbook(ret).setIsBorrow("好");
            System.out.println("借阅成功");
        }else{
            System.out.println("要借阅的书不存在");
        }
    }
}
